package com.sky.controller.admin;

import com.sky.dto.BookDTO;
import com.sky.dto.BookPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @Description: 书籍相关
 * @Author: Qiuyan
 * @Date: 2025-04-12 23:20
 * @Version： 1.0
 **/
@RestController
@RequestMapping("/admin/book")
@Slf4j
@Api(tags="书籍相关接口")
public class BookController {

    @Autowired
    private BookService bookService;

    /**
     * 新增书籍
     * @param bookDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增书籍")
    public Result save(@RequestBody BookDTO bookDTO) {
        log.info("新增书籍：{}", bookDTO);
        bookService.saveWithImage(bookDTO);
        return Result.success();
    }

    /**
     * 书籍分页查询
     * @param bookPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("书籍分页查询")
    public Result<PageResult> page(BookPageQueryDTO bookPageQueryDTO) {
        log.info("书籍分页查询：{}", bookPageQueryDTO);
        PageResult pageResult = bookService.pageQuery(bookPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 更新书籍状态
     * @param status Available/Lent
     * @param id 书籍id
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("设置书籍状态")
    public Result<String> updateStatus(@PathVariable String status, Long id) {
        log.info("更新书籍状态：status={}, id={}", status, id);
        bookService.updateStatus(status, id);
        return Result.success();
    }
}
